<?

$PROJECT = $data;

$USERS = $PROJECT->GetRelated('users');

$projectMembers = $PROJECTUSERS = array();
foreach($USERS as $U){
    $user = $U->GetRelated('user');
    $PROJECTUSERS[] = $user;
    array_push($projectMembers, $user->GetLink());
}

$status_test = Task::model()->rstatuses[TaskModule::t('fields', 'Ожидает проверки')];
$crit_test = new CDbCriteria;
$crit_test->addColumnCondition(array(
    'project_id' => $PROJECT->id,
    'user_id' => Yii::app()->user->id,
    'status' => $status_test
));
$TASK_TO_TEST = Task::model()->findAll($crit_test);

$status_away = Task::model()->rstatuses[TaskModule::t('fields', 'В очереди')];
$crit_away = new CDbCriteria;
$crit_away->addColumnCondition(array(
    'project_id' => $PROJECT->id,
    'status' => $status_away
));
$TASK_TO_AWAY = Task::model()->findAll($crit_away);

?><li class="project">
    <a href="<?=$this->createUrl('task/list',array('project'=>$PROJECT->code))?>">[<?=$PROJECT->code?>]</a>
    <big><?=$PROJECT->name?></big><br />
    <?if(!empty($projectMembers)){ echo TaskModule::t('app', 'Участники проекта').':'; echo implode(', ', $projectMembers); }?>
    
    <div class="container">
        <?if(count($TASK_TO_TEST) > 0){?>
            <b>Задачи, ожидающие проверки (<?=count($TASK_TO_TEST)?>)</b>
            <ul class="tasktest">
            <?
            $i = 0;
            foreach($TASK_TO_TEST as $TASK){
                $i++;
                
                $url = $this->createUrl('task/list',array('project'=>$PROJECT->code,'tid'=>$TASK->id));
                echo '<li class="task"><a href="'.$url.'">'.substr_word(strip_tags($TASK->text)).'</a></li>';
                
                if($i == 5) break;
            }
            if(count($TASK_TO_TEST) > 5){
                $url = $this->createUrl('task/list',array('project'=>$PROJECT->code,'filter[status]'=>$status_test));
                echo '<li class="alltask"><a href="'.$url.'">Все задачи ожидающие проверки</a></li>';
            }
            ?>
            </ul>
        <?}?>
        <?if(count($TASK_TO_AWAY) > 0){?>
            <b>Задачи, ожидающие выполнения (<?=count($TASK_TO_AWAY)?>)</b>
            <ul class="taskaway">
            <?
            $i = 0;
            foreach($TASK_TO_AWAY as $TASK){
                $i++;
                
                $url = $this->createUrl('task/list',array('project'=>$PROJECT->code,'tid'=>$TASK->id));
                echo '<li class="task"><a href="'.$url.'">'.substr_word(strip_tags($TASK->text)).'</a></li>';
                
                if($i == 5) break;
            }
            if(count($TASK_TO_AWAY) > 5){
                $url = $this->createUrl('task/list',array('project'=>$PROJECT->code,'filter[status]'=>$status_test));
                echo '<li class="alltask"><a href="'.$url.'">Все задачи ожидающие проверки</a></li>';
            }
            ?>
            </ul>
        <?}?>
    </div>
    
</li>
